import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:p_location/common/widget/avartar_view.dart';
import 'package:p_location/common/widget/tag_view.dart';
import 'package:p_location/home/obj/area_person_obj.dart';
import 'package:p_location/home/ui/person/page_employee_detail.dart';
import 'package:p_location/home/ui/person/page_guest_detail.dart';
import 'package:p_location/home/ui/person/page_worker_detail.dart';
import 'package:p_location/map/jaguar_demo.dart';
import 'package:p_location/map/res/search_person_detail.dart';
import 'package:p_location/map/ui/page_person_trace.dart';
import 'package:p_location/map/ui/page_search_person.dart';
import 'package:p_location/net/dio_http_client.dart';
import 'package:p_location/utils/navigator_util.dart';

class CellAreaPersonInfo extends StatelessWidget {
  final AreaPersonObj _personObj;

  const CellAreaPersonInfo(this._personObj);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        print(_personObj.typeName);
        if (_personObj.type == "内部员工") {
          NavigatorUtil.push(
              context, PageEmployeeDetail(_personObj.id, _personObj.name));
        } else if (_personObj.type == "承包商") {
          NavigatorUtil.push(context, PageWorkerDetail(_personObj.id));
        } else if (_personObj.type == "外来访客") {
          NavigatorUtil.push(context, PageGuestDetail(_personObj.id));
        }
      },
      child: Container(
        color: Colors.transparent,
        child: Stack(
          alignment: Alignment.centerLeft,
          children: <Widget>[
            Card(
              margin: EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Row(
                children: [
                  AvatarView(_personObj.picId == null
                      ? ""
                      : '${DioHttpClient.baseUrl}/image/view?id=${_personObj.picId}'),
                  Container(
                    height: 120,
                    margin: EdgeInsets.only(left: 15),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Text(
                          _personObj.name,
                          style: TextStyle(
                            fontSize: 16,
                          ),
                        ),
                        Container(
                          constraints: BoxConstraints(
                            maxWidth: 200,
                          ),
                          child: Text(
                            '部门：${_personObj.departName}',
                            style: TextStyle(fontSize: 14, color: Colors.grey),
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        Container(
                          constraints: BoxConstraints(
                            maxWidth: 200,
                          ),
                          child: Text(
                            '岗位：${_personObj.jobName}',
                            style: TextStyle(fontSize: 14, color: Colors.grey),
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        Wrap(
                          children: [
                            TagView(
                              "实时跟踪",
                              paddingLeft: 10,
                              paddingRight: 10,
                              paddingTop: 3,
                              paddingBottom: 3,
                              radius: 5,
                              strokeColor: Color.fromARGB(255, 56, 160, 253),
                              textColor: Color.fromARGB(255, 56, 160, 253),
                              fillColor: Colors.white,
                              onPress: (){
                                SearchPersonDetail target = SearchPersonDetail();
                                target.id = _personObj.id;
                                target.sn = _personObj.sn;
                                target.name = _personObj.name;
                                target.typeName = _personObj.typeName;
                                target.jobName = _personObj.jobName;
                                target.departName = _personObj.departName;
                                NavigatorUtil.push(context, GisMapPage(realTrackTarget:target));
                              },
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 8),
                              child: TagView(
                                  "查询轨迹",
                                  paddingLeft: 10,
                                  paddingRight: 10,
                                  paddingTop: 3,
                                  paddingBottom: 3,
                                  radius: 5,
                                  strokeColor: Color.fromARGB(255, 56, 160, 253),
                                  textColor: Color.fromARGB(255, 56, 160, 253),
                                  fillColor: Colors.white,
                                  onPress: () {
                                    SearchPersonDetail detail = SearchPersonDetail();
                                    detail.name = _personObj.name;
                                    detail.sn = _personObj.sn;
                                    NavigatorUtil.push(context, PagePersonTrace(
                                      isSingleTrace: true, chosenSn: detail,));
                                  }
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
